package com.wanger.swa.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wanger.swc.model.Result;
import com.wanger.swa.domain.myEnum.UserEnum;
import com.wanger.swa.dto.user.query.UserQuery;
import com.wanger.swa.dto.user.req.UserAddReq;
import com.wanger.swa.dto.user.req.UserUpdateReq;
import com.wanger.swa.dto.user.resp.UserResp;
import com.wanger.swa.service.ise.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author: wanger
 * @Date: 2024/9/15 12:52
 * @Description: 用户
 */
@RestController
@Api(tags = "用户")
@RequiredArgsConstructor
@RequestMapping("/user")
public class UserController {

    private final UserService userService;

    @ApiOperation("添加用户")
    @PostMapping("/addUser")
    public Result<UserResp> addUser(@RequestBody UserAddReq addDTO) {
        return Result.ok(userService.addUser(addDTO));
    }

    @ApiOperation("修改用户")
    @PutMapping("/updateUser")
    public Result<UserResp> updateUser(@RequestBody UserUpdateReq updateDTO) {
        return Result.ok(userService.updateUser(updateDTO));
    }

    @ApiOperation("用户详情")
    @GetMapping("/getOneUser")
    public Result<UserResp> getOneUser(String id) {
        return Result.ok(userService.getOneUser(id));
    }

    @ApiOperation("分页查询用户")
    @GetMapping("/pageUser")
    public Result<IPage<UserResp>> pageUser(UserQuery query) {
        return Result.ok(userService.pageUser(query));
    }

    @ApiOperation("用户列表查询")
    @GetMapping("/listUser")
    public Result<List<UserResp>> listUser(UserQuery query) {
        return Result.ok(userService.listUser(query));
    }

    @ApiOperation("删除用户")
    @DeleteMapping("/deleteUser")
    public Result<Void> deleteUser(String id) {
        userService.deleteUser(id);
        return Result.ok();
    }

    @ApiOperation("用户枚举")
    @GetMapping("/getEnumUser")
    public Result<Map<String, List<Map<String, String>>>> getEnumUser() {
        return Result.ok(UserEnum.getList());
    }
}
